import request from '@/utils/request'

const mf_MyTaskUndoApi = {
  taskList: 'flow/taskList',
  collectBusinessList: "/flow/collectBusinessList",
  detailsBusinessList: "/flow/detailsBusinessList",
  suspendBusinessList: 'flow/suspendBusinessList',
  queryComment: 'flow/queryComment',
  taskExec: 'flow/taskExec',
  terminationTask: 'flow/terminationTask',
  delegate: 'flow/delegate',
  findBehindTaskExecuser: 'flow/findBehindTaskExecuser',
  backProcess: "flow/backProcess",
  getTaskdefList: "flow/getTaskdefList",
  queryLastComment: "flow/queryLastComment",
  export: "/flow/export",
}

	/**
	 * 查询当前可驳回的流程节点
	 * @param stepid        当前环节id
	 * @param processinstanceid (流程实例id, 对应act_ru_execution表PROC_INST_ID_字段)
   * @param result 结果集
	 * @return
	 */
export function getTaskdefList(stepid, processinstanceid, result) {
  return request({
    url: mf_MyTaskUndoApi.getTaskdefList,
    method: 'post',
    params: {stepid, processinstanceid}
  })
}


/*
  驳回
*/
export function backProcess(params,body) {
  return request({
    url: mf_MyTaskUndoApi.backProcess,
    method: 'post',
    params: params,
    data: body
  })
}



/*
  获取整个流程节点的执行成员
*/
export function findBehindTaskExecuser(parameter) {
  return request({
    url: mf_MyTaskUndoApi.findBehindTaskExecuser,
    method: 'post',
    params: parameter
  })
}

/**
 * 查询只要父流程列表
 * @param userid
 * @param pageinfo
 */
 export function collectBusinessList(parameter, data) {
  return request({
    url: mf_MyTaskUndoApi.collectBusinessList,
    method: 'post',
    params: parameter,
    data: data
  })
}

/**
 * 查询只要子流程的详细列表
 * @param userid
 * @param pageinfo
 */
 export function detailsBusinessList(parameter, data) {
  return request({
    url: mf_MyTaskUndoApi.detailsBusinessList,
    method: 'post',
    params: parameter,
    data: data
  })
}

/**
 * 个人的待办任务
 * @param userid
 * @param pageinfo
 */
export function queryMf_MyTaskUndoList(parameter, data) {
  return request({
    url: mf_MyTaskUndoApi.taskList,
    method: 'post',
    params: parameter,
    data: data
  })
}

/**
 * 个人的挂起任务
 * @param userid
 * @param pageinfo
 */
 export function suspendBusinessList (parameter, data) {
  return request({
    url: mf_MyTaskUndoApi.suspendBusinessList,
    method: 'post',
    params: parameter,
    data: data
  })
}

/**
 * 查询流程处理记录
 * @param processinstanceid 流程定义id
 */
export function queryComment(parameter) {
  return request({
    url: mf_MyTaskUndoApi.queryComment,
    method: 'post',
    params: parameter
  })
}

/**
 * 获取进行中流程实例填写的表单数据
 * @param processinstanceid 流程定义id
 */
 export function queryLastComment(processinstanceid) {
  return request({
    url: mf_MyTaskUndoApi.queryLastComment,
    method: 'post',
    params: {processinstanceid: processinstanceid}
  })
}

/**
 * 通过/驳回待办任务
 * @param taskid 流程业务id
 * @param userid
 * @param processinstanceid 流程实例id
 * @param approved 审批结果是否同意
 * @param remark 审批意见
 */
export function taskExec(parameter, body) {
  return request({
    url: mf_MyTaskUndoApi.taskExec,
    method: 'post',
    params: parameter,
    data: body
  })
}

/**
 *终止待办任务
 * @param processinstanceid 流程实例id
 * @param deleteReason 终止原因
 */
export function terminationTask(parameter, serviceList = []) {
  return request({
    url: mf_MyTaskUndoApi.terminationTask,
    method: 'post',
    params: parameter,
    data: serviceList
  })
}

/**
 * 委托待办任务
 * @param taskid 业务id
 * @param userid 委托人的userid
 * @param entrustuserid 被委托人userid
 */
export function delegate(parameter) {
  return request({
    url: mf_MyTaskUndoApi.delegate,
    method: 'post',
    params: parameter
  })
}

/**
 * 导出待处理任务列表
 */
 export function output(userid, pageinfo) {
  let cppageinfo = JSON.parse(JSON.stringify(pageinfo))
  cppageinfo.pageSize = 2147483647
  cppageinfo.pageNumber = 1
  return request({
    url: mf_MyTaskUndoApi.export,
    method: 'post',
    params: { userid },
    data: cppageinfo,
    responseType: 'blob'
  })
}